﻿Public Class frm_list_smk
    Sub cmb_group_search()
        cmb_group.Items.Add("No Pendaftaran")
        cmb_group.Items.Add("Nama Pendaftar")
        cmb_group.Items.Add("No Uan")
    End Sub
    Sub BuatTable()
        With lv_smk.Columns
            .Clear()
            .Add("No", 45, HorizontalAlignment.Right) '0
            .Add("Tanggal Pendaftaran", 140, HorizontalAlignment.Center) '1
            .Add("Asal Pendaftar", 140, HorizontalAlignment.Center) '2
            .Add("Asal Sekolah", 150, HorizontalAlignment.Center) '3
            .Add("Jenis Kelamin", 90, HorizontalAlignment.Center) '4
            .Add("No. Pendaftaran", 145, HorizontalAlignment.Center) '5
            .Add("Nama", 140, HorizontalAlignment.Left) '6
            .Add("B. Indo", 50, HorizontalAlignment.Right) '7
            .Add("B.Inggris", 50, HorizontalAlignment.Right) '8
            .Add("Matematika", 50, HorizontalAlignment.Right) '9
            .Add("IPA", 50, HorizontalAlignment.Right) '10
            .Add("Agama", 50, HorizontalAlignment.Right) '11
            .Add("IPS", 50, HorizontalAlignment.Right) '12
            .Add("Pkn", 50, HorizontalAlignment.Right) '13
            .Add("Total Nilai", 80, HorizontalAlignment.Right) '14
            .Add("Pilihan 1", 190, HorizontalAlignment.Left) '15
            .Add("Jurusan 1", 190, HorizontalAlignment.Left) '16
            .Add("Pilihan 2", 190, HorizontalAlignment.Left) '17
            .Add("Jurusan 2", 190, HorizontalAlignment.Left) '18
        End With
        lv_smk.GridLines = True
        lv_smk.View = View.Details
        lv_smk.FullRowSelect = True
    End Sub
    Private Sub frm_list_smk_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmb_group_search()
        BuatTable()
        cmb_group.SelectedIndex = 0
        DB.FlushCache()
        DB.Selects("*")
        DB.From("tbl_pendaftaran_smk")

        Connection.ExecuteToDataReader(DB.GetQueryString)

        If Connection.Read.HasRows Then

            With Connection.Read
                Dim numb As Integer

                numb = 0
                While .Read
                    Dim asal_pendaftar As String
                    numb = numb + 1
                    lv_smk.Items.Add(numb)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(1).ToString.Split(" ")(0))
                    If .Item(2).ToString = 0 Then
                        asal_pendaftar = "Dalam Kota"
                    Else
                        asal_pendaftar = "Luar Kota"
                    End If
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(asal_pendaftar)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(10).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(7).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(3).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(6).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(11).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(12).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(13).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(14).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(15).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(16).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(17).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(18).ToString, 2))

                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(ListSekolah.getNama(.Item(20).ToString))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(21).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(ListSekolah.getNama(.Item(22).ToString))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(23).ToString)
                End While

            End With

        End If

    End Sub

    Private Sub lv_smk_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lv_smk.DoubleClick
        Dim no_unique
        If lv_smk.Items.Count > 0 Then
            'frm_smp_edit.lblid.Text = ListView1.SelectedItems(0).Text
            no_unique = lv_smk.SelectedItems(0).SubItems(5).Text
            frm_smk_edit.MdiParent = frm_main
            frm_smk_edit.WindowState = FormWindowState.Maximized
            frm_smk_edit.Show()
            frm_smk_edit.InitData(no_unique)
            frm_smk_edit.Focus()
        End If
        'Me.Dispose()
        'Me.Close()
    End Sub


    Private Sub cmd_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_search.Click

        Dim group_filter As String
        group_filter = cmb_group.SelectedIndex
        Select Case group_filter
            Case "0"
                group_filter = "no_pendaftaran"
            Case "1"
                group_filter = "nama_pendaftar"
            Case "2"
                group_filter = "no_uan"
        End Select

        DB.FlushCache()
        DB.Selects("*")
        DB.From("tbl_pendaftaran_smk")
        DB.Where("WHERE " & group_filter & " LIKE '%" & txt_search.Text & "%'")

        Connection.ExecuteToDataReader(DB.GetQueryString)
        lv_smk.Items.Clear()
        If Connection.Read.HasRows Then

            With Connection.Read
                Dim numb As Integer

                numb = 0
                While .Read
                    Dim asal_pendaftar As String
                    numb = numb + 1
                    lv_smk.Items.Add(numb)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(1).ToString.Split(" ")(0))
                    If .Item(2).ToString = 0 Then
                        asal_pendaftar = "Dalam Kota"
                    Else
                        asal_pendaftar = "Luar Kota"
                    End If
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(asal_pendaftar)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(10).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(7).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(3).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(6).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(11).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(12).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(13).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(14).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(15).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(16).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(17).ToString, 2))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(FormatNumber(.Item(18).ToString, 2))

                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(ListSekolah.getNama(.Item(20).ToString))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(21).ToString)
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(ListSekolah.getNama(.Item(22).ToString))
                    lv_smk.Items.Item(lv_smk.Items.Count - 1).SubItems.Add(.Item(23).ToString)
                End While

            End With

        End If
    End Sub

    Private Sub lv_smk_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv_smk.SelectedIndexChanged

    End Sub
End Class